﻿module Program
open System
open ABSTRACT_INTERPRETER_ALGORITHM
let samplesDir = "C:\\SMLNJ\\svn\\MSc\\SamplePrograms\\"
ContextGraph.debug := false;

//let ast1 = BJKParse.aFile(samplesDir + "amir1.core");
//let ast2 = BJKParse.aFile(samplesDir + "amir2.core");
//let ast3 = BJKParse.aFile(samplesDir + "amir3.core");
//let ast31 = BJKParse.aFile(samplesDir + "amir3.1.core");
//let ast4 = BJKParse.aFile(samplesDir + "amir4.core");
//let ast5 = BJKParse.aFile(samplesDir + "sample1.core");
try
    let ast6 = Parser.parseFile(samplesDir + "sample5.core");

    let ast = ast6;

    printfn "%s"
      ("============================================\n" +
      "analysed program:\n" +
      (Core.prt ast) +
      "============================================\n");

    printfn "\nPress any key to start analysis..."
    let _ = Console.ReadKey()
    let absInt = AbstractInterpreter()
    let g = absInt.analyse(ast)

    let edgeCount = ref 0
    for p in g.Keys do
        for qd in g.[p] do
            edgeCount := !edgeCount + 1
    printfn "Finished!\nPress any key to continue..."
    let _ = Console.ReadKey()
    printfn "%s"
          ("New abstract interpreter algorithm analysis result:\n" +
          ContextGraph.prtEdges(g) +
          "============================================\n");
  (*  printfn "%s"
          ("Original BJK algorithm Poly analysis result:\n" +
           ContextGraph.prtDfr(Pol.analyse(ast)) +
           "\n============================================\n");
*)
    printfn "result graph contains %d edges.\nPress any key to exit..."  (!edgeCount)
with
    | Failure s -> printfn "%s\n" ("Fatal error occured at " + s)
    | _ -> ()
let _ = Console.ReadKey()